<?php
namespace app\controller;

use app\BaseController;
use app\model\UserInfoHobby;

use app\model\UserInfos;
use think\Request;
use think\facade\View;
use think\facade\Session;
// 使用模板引擎

class UserInfo extends BaseController{


    protected $request;

    /**
     * 构造方法
     * @param Request $request Request对象
     * @access public
     */
    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function index(){
        // 切换模板，需要将当前的模板视图false掉
        view::engine()->layout(false);
        view::engine()->layout('userlayout');
        return view::fetch();
    }

    // 完善个人信息
    public function saveUserInfo(){
        // 获取前端的表单数据
        $data =$this->request->param();
        //dump($data);

        $uid = $data["uid"];
//        $uid ="robin3";
//        dump($data);
//        // 基本信息存储
        $userinfo = new UserInfos();
        $userinfo->saveUserInfo($data);

        // 兴趣爱好存储
        $infoHobby = new UserInfoHobby();
       // dump($data["hobby"]);

        $hblist = [
            "Java"=>false,
            "Python"=>false,
            "PHP"=>false,
            "HTML"=>false,
            "CSS"=>false,
            "JS"=>false,
            "C"=>false,
            "Golang"=>false,
            "Ruby"=>false,
            "Rust"=>false
        ];

        //dump($hblist);
        //dump($hblist);

        $hb = $data["hobby"];
        //dump($hb);


        foreach ($hb as $v){
            $hblist["$v"]=true;
        }
        unset($hblist[""]);
        unset($hblist[" "]);


        $infoHobby->saveHobby($hblist,$uid);

        return 1;
    }



}